<?php
class Usuarios extends CI_Controller
{

    function __construct()
    {
        parent :: __construct();
        $this->load->helper('comunes');
    }

    function index()
    {
        $data['header'] = $this->load->view('usuarios/login', array(), true);
        $this->load->view('template', $data);
    }

    function showcontrolpanel()
    {
        checkvaliduser();
        $this->load->model('usuarios_model');
        $id = $this->session->userdata('id_usuario');
        $a['nombredelusuariologeado'] = $this->usuarios_model->get($id)->usu_nombre;
        $this->load->model('reporte_model');
        $a['opcionescombo'] = $this->reporte_model->opcionesdecarreras();
        $this->load->model('reporte_model_posgrado');
        $a['opcionescombo_posgrado'] = $this->reporte_model_posgrado->opcionesdecarreras();
        $this->load->helper('form');
        $data['header'] = $this->load->view('controlpanel', $a, true);
        $this->load->view('template', $data);
    }

    function checklogin()
    {
        if ($this->input->is_ajax_request())
        {
            $nick = $this->input->post('nick');
            $clave = $this->input->post('clave');
            $this->load->model('usuarios_model');
            $data = $this->usuarios_model->checklogin_in_DB($nick, $clave);
            echo json_encode($data);
        }
    }

    function logout()
    {
        $this->session->sess_destroy();
        redirect($this->config->item('url_exit'));
    }

    function catalogo()
    {
        checkvaliduser();
        $this->load->model('usuarios_model');
        $param['grid'] = $this->usuarios_model->griddeusuario();
        $data['content'] = $this->load->view('usuarios/seguridad', $param, true);
        $this->load->view('template', $data);
    }

    function getData()
    {
        if ($this->input->is_ajax_request())
        {
            $this->load->library('datagrid');
            $grid = $this->datagrid;
            $response = $grid->getData('usuarios', array(array()), array(), false, 'usu_id > 0');
            $rs = $grid->jsonresult($response);
            echo $rs;
        }
    }

    function setData()
    {
        if ($this->input->is_ajax_request())
        {
            $this->load->library('datagrid');
            $grid = $this->datagrid;
            $response = $grid->operations('usuarios', 'usu_id');
        }
    }
}
